从treeview选择中抓取超链接并在浏览器中打开它应该非常简单 import webbrowser as wb
def open_link(event):
tree = event.widget # get the treeview widget
item = tree.item(tree.focus()) # get the treeview selection
link = item['values'][1] # get the link from the selected row
wb.open_new_tab(link) # open the link in a browser tab
# bind the selection event to 'open_link'
my_tree.bind('', open_link) 请注意,当您从treeview中选择项时,即当您单击表的一行时,这将触发,而不是在第二列中专门单击超链接。如果你想这么做,你必须更特别. import webbrowser as wb
def open_link(event):
tree = event.widget # get the treeview widget
region = tree.identify_region(event.x, event.y)
col = tree.identify_column(event.x)
iid = tree.identify('item', event.x, event.y)
if region == 'cell' and col == '#2':
link = tree.item(iid)['values'][1] # get the link from the selected row
wb.open_new_tab(link) # open the link in a browser tab
# bind left-click to 'open_link'
my_tree.bind('', open_link)现在,只有当用户单击“超级链接”列中的链接时,该链接才会打开。
|